<?php
session_start();
include 'op/CheckEventDate.php';
$ctr2 = -1;

//if($_SESSION['UserType']=='user')
if (!$_SESSION['loggedin']) {
    // User not logged in, redirect to login page
    echo "<script language='javascript'>window.location='Home.php'</script>";
}
if ($_SESSION['usertype'] == 'user') {
?>

    <html>
        <head>
            <title>LFP - Looking for Party</title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <style type="text/css">
                <!--
                a:link {  color: #FFFFFF; text-decoration: none}

                a:visited {  text-decoration: none; color: #FFCC66}

                a:hover {  color: #99CCFF; text-decoration: underline}
                body {  font-family: "Arial", "Helvetica", "sans-serif"}
                -->
            </style>
        </head>
        <body bgcolor="#FFFACD" link="#FFFFFF">

            <table style="background: url('image/logo.gif')" width="990" border="0" cellspacing="0" cellpadding="0" style="height:100px" align="center" >
                <tr style="background: url('image/logo.gif')">
                    <td colspan="1">
                        <FONT FACE="Tahoma" SIZE="6">.</FONT>
                        <pre><FONT FACE="Tahoma">.</FONT>
                        </pre>
                    </td>
                </tr>
            </table>

            <table width="990" border="0" cellspacing="0" cellpadding="0" style="height:20px" align="center">
                <tr bgcolor="#000000">
                    <td BGCOLOR="#336666"> <div align="center">
                            <font color="#FFFFFF" face="Tahoma">|</font>
                            <font face="Tahoma">
                                <a href="Home.php">Home</a>
                                <font color="#FFFFFF">|</font>

                                <a href="UserReserveEvent.php">Reserve Event</a> <font color="#FFFFFF">|</font>
                                <a href="UserMyReservation.php">My Reservation</a><font color="#FFFFFF">|</font>
                                <a href="UserContactUs.php">Contact Us</a><font color="#FFFFFF">|</font>
                            </font>
                        </div>
                    </td>
                </tr>
            </table>

            <table width="990" border="0" cellspacing="0" cellpadding="0" height="13" style="background: url('image/ktop1.gif')" align="center">
                <tr>
                    <td>
                        <FONT FACE="Tahoma"><img alt=""  src="image/pixel.gif" width="1" style="height:1px">
                        </FONT>
                    </td>
                </tr>
            </table>

            <FONT FACE="Tahoma"><br> </FONT>
            <table width="990" border="0" cellspacing="0" cellpadding="0" align="center">

                <tr>
                    <td valign="top" width="245">

                        <table width="215" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td colspan="3" height="28" style="background: url('image/kmenuup.gif')" >
                                    <div align="center">
                                        <FONT color="#0000F9" FACE="Tahoma">
                                            <b>User</b>
                                        </FONT>
                                    </div>
                                </td>
                            </tr>
                            <tr> <td width="9" height="76" style="background: url('image/kmenuleft.gif')">&nbsp;
                                </td>
                                <td width="194" height="76">


                                    <FONT FACE="Tahoma"><br> <font color=#000000 >

                                        <?php
                                        include 'op/UserWelcome.php';
                                        ?>

                                        &nbsp; &nbsp;<input type="button" name="register" value ="Edit Profile" onClick="parent.location='UserEditProfile.php'"/><input type="button" name="register" value ="&nbsp;&nbsp;&nbsp;Logout&nbsp;&nbsp;&nbsp;" onClick="parent.location='Logout.php'"/>


                                    </font></FONT>
                            </td>
                            <td width="12" height="76" style="background: url('image/kmenuright.gif')" >&nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" height="28" style="background: url('image/kmenudown.gif')">&nbsp;
                            </td>
                        </tr>
                    </table>
                    <table width="215" border="0" cellspacing="0" cellpadding="0">
                        <tr> <td colspan="3" height="28" style="background: url('image/kmenuup.gif')">
                                <div align="center">
                                    <FONT color="#0000F9" FACE="Tahoma">
                                        <b>Latest Event</b>
                                    </FONT>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td width="9" height="76" style="background: url('image/kmenuleft.gif')" >&nbsp;
                            </td>
                            <td width="194" height="76">
                                <FONT FACE="Tahoma">

                                    <?php
                                        include 'op/LatestEvent.php';
                                    ?>

                                    </FONT>
                                </td>
                                <td width="12" height="76" style="background: url('image/kmenuright.gif')">&nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td colspan="3" height="28" style="background: url('image/kmenudown.gif')">&nbsp;
                                </td>
                            </tr>
                        </table>

                        <FONT FACE="Tahoma"><br></FONT>

                        <table width="215" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td colspan="3" height="28" style="background: url('image/kmenuup.gif')">
                                    <div align="center">
                                        <b><font face="Tahoma" color="#0000F9">Canceled Events</font></b>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td width="9" height="137" style="background: url('image/kmenuleft.gif')">&nbsp;</td>
                                <td width="194" height="137">
                                <?php
                                        include 'op/CanceledEvent.php';
                                ?>
                                    </td><td width="12" height="137" style="background: url('image/kmenuright.gif')">&nbsp;</td></tr>
                                <tr> <td colspan="3" height="28" style="background: url('image/kmenudown.gif')">&nbsp;</td></tr>
                            </table>
                        </td>

                        <td width="745" valign="top">
                            <table width="745" border="0" cellspacing="0" cellpadding="0" style="background: url('image/klongmenu.gif')"  height="34">
                                <tr> <td><b><font face="Tahoma">Reserve Event</font>
                                        </b>
                                    </td>
                                </tr>
                            </table>

                    <?php
                                        if (isset($_POST['Go'])) {
                                            $eventtype = $_POST['fet'];
                                            $status = $_POST['status'];
                                        }
                    ?>

                                        <form name="filter" method="post" action="">
                                            <select title="- Select Type -" name="fet" >

                                                <option value="All" SELECTED >- Category (All) -</option>
                            <?php
                                        include 'DBLibrary/config.php';
                                        include 'DBLibrary/openDB.php';
                                        mysql_select_db($dbname);
                                        $resArrCategory = mysql_query("SELECT * FROM eventcategory");

                                        while ($rowCat = mysql_fetch_array($resArrCategory)) {
                            ?>
                                            <option value="<?php echo $rowCat['CategoryName']; ?>" <?php if ($eventtype == $rowCat['CategoryName'])
                                                echo "SELECTED"; ?> ><?php echo "Category ( " . $rowCat['CategoryName'] . " )"; ?></option>
                                    <?php } ?>
                            </select>

                            <select title="- Select Type -" name="status" >
                                <option value="0" SELECTED >- Select Status ( All )-</option>

                                <option value="Open" <?php
                                        if ($status == "Open") {
                                            echo "SELECTED";
                                        }
                                    ?>>Select Status ( Open )</option>
                                        <option value="Closed" <?php
                                        if ($status == "Closed") {
                                            echo "SELECTED";
                                        } ?>>Select Status ( Closed )</option>
                                <option value="Completed" <?php
                                        if ($status == "Completed") {
                                            echo "SELECTED";
                                        }
                                    ?>>Select Status ( Completed )</option>
                                <option value="Canceled" <?php
                                        if ($status == "Canceled") {
                                            echo "SELECTED";
                                        }
                                    ?>>Select Status ( Canceled )</option>


                            </select>

                            <input type="submit" name="Go" value="Go"/>
                        </form>

                    <?php
                                        if (isset($_POST['Add'])) {

                                            $EventID = $_POST['EventID'];

                                            include 'DBLibrary/config.php';
                                            include 'DBLibrary/openDB.php';
                                            mysql_select_db($dbname);
                                            // md5 hash
                                            $tempuser = $_SESSION['username'];

                                            $query5 = "INSERT INTO reservation(username, EventID)
VALUES('$tempuser', '$EventID') ";
                                            mysql_query($query5) or die('Reservation Failed');

                                            $query6 = "update event set NumberOfAttendees = NumberOfAttendees +'1' where EventID ='" . $EventID . "' and NumberOfAttendees<MaxSlot";
                                            mysql_query($query6);

                                            echo "Successful";
                                            include 'DBLibrary/closeDB.php';
                                        }
                    ?>



                    <?php
                                        if (isset($_POST['Go'])) {
                                            mysql_select_db($dbname);
                                            $queryforevent = "select * from event where EventID!=0";

                                            $queryM = $queryforevent;

                                            $resArrCategory = mysql_query("SELECT * FROM eventcategory");
                                            while ($rowCat = mysql_fetch_array($resArrCategory)) {
                                                if ($eventtype == $rowCat['CategoryName'])
                                                    $queryM.= "  and EventType=\"" . $rowCat['CategoryName'] . "\" ";
                                            }
                                            if ($status == "Open")
                                                $queryM.= "  and Status=\"Open\" ";

                                            if ($status == "Completed")
                                                $queryM.= "  and Status=\"Completed\" ";

                                            if ($status == "Canceled")
                                                $queryM.= "  and Status=\"Canceled\" ";

                                            if ($status == "Closed")
                                                $queryM.= "  and Status=\"Closed\" ";


//echo $queryM;

                                            $getevent = mysql_query($queryM);
                                            $ctr2 = 0;
                                            while ($rowevent = mysql_fetch_array($getevent)) {
                                                $ctr2++;
                                            }
                                            if ($ctr2 != -1) {
                                                echo "<h4>Total Retrieved = " . $ctr2 . "</h4>";
                                                if ($ctr2 == 0)
                                                    echo "No Results<br><br>";
                                            }

                                            $getevent = mysql_query($queryM);
                                            $ctr = 0;
                                            while ($rowevent = mysql_fetch_array($getevent)) {
                    ?>

                                            <form method="post" action="">
                        <?php
                                                $ctr++;
                                                /* <input type="text" name="eventname" value="<?php echo $row['EventName']?>" size="1" maxlength="64"  style="visibility:hidden;"/>
                                                 */
                                                echo "<FONT COLOR=\"#0000F9\" FACE=\"Tahoma\"><b>" . $ctr . ". " . $rowevent['EventName'] . "</b></FONT> by <FONT COLOR=\"#0000F9\" FACE=\"Tahoma\"><b>" . $rowevent['AdminName'] . "</FONT> Status: " . $rowevent['Status'] . "</b>";

                                                echo "<br>";
                                                echo $rowevent['EventDescription'] . "<br>";
                                                echo "<FONT COLOR=\"#707070\" FACE=\"Tahoma\"><small>Category: " . $rowevent['EventType'] . " - Number of Attendess: " . $rowevent['NumberOfAttendees'] . "/" . $rowevent['MaxSlot'] . " - Date & Time: " . $rowevent['EventDateTime'] . " - Location: " . $rowevent['Location'] . "</small></FONT><br>";


                                                $query13 = "SELECT count(ResID) FROM reservation where EventID ='" . $rowevent['EventID'] . "' and username='" . $_SESSION['username'] . "'";

                                                $Arr1 = mysql_fetch_array(mysql_query($query13));
                                                //echo $Arr1[0];
                                                if ($rowevent['NumberOfAttendees'] < $rowevent['MaxSlot'] && $Arr1[0] == 0 && $rowevent['Status'] != "Canceled" && $rowevent['Status'] != "Completed") {
                        ?>
                                                    <input type="submit" name="Add" value="Add"/> <?php
                                                }
                                                echo "<input type=\"text\" name=\"EventID\" size=\"1\" value=\"" . $rowevent['EventID'] . "\" style=\"visibility:hidden;\"/> ";


                                                if ($rowevent['Status'] == "Completed")
                                                    echo "<FONT COLOR=\"#FF0000\" FACE=\"Tahoma\">Sorry, this event is done </FONT>";


                                                else if ($rowevent['NumberOfAttendees'] == $rowevent['MaxSlot'])
                                                    echo "<FONT COLOR=\"#FF0000\" FACE=\"Tahoma\">Sorry, Closed Already</FONT>";


                                                else if ($Arr1[0] == 1)
                                                    echo "<FONT COLOR=\"#FF0000\" FACE=\"Tahoma\">You already have reserved this event</FONT>";
                                                else if ($rowevent['Status'] == "Canceled")
                                                    echo "<FONT COLOR=\"#FF0000\" FACE=\"Tahoma\">Sorry, this event have been canceled </FONT>";
                        ?>
                                                </form> <?php
                                                echo "<br>";
                                            }
                                        }
                        ?>


                                    </td>
                                </tr>
                            </table>

                            <FONT FACE="Tahoma"><br> </FONT>
                            <table width="990" border="0" cellspacing="0" cellpadding="0" align="center">
                                <tr>
                                    <td>
                                        <div align="left"></div>
                                        <DIV ALIGN="CENTER">
                                            <FONT SIZE="2" FACE="Tahoma">Copyright 2010 Bilis Taxi. All Rights Reserved</FONT>
                                        </DIV>
                                        <TABLE WIDTH="990" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="20" ALIGN="center">
                                            <TR BGCOLOR="#000000">
                                                <TD BGCOLOR="#336666">&nbsp;
                                                </TD>
                                            </TR>
                                        </TABLE>
                                    </td>
                                </tr>
                            </table>
                            <FONT FACE="Tahoma"></FONT>

                        </body>
                    </html>

<?php
                                    }
                                    if ($_SESSION['usertype'] == 'admin') {
                                        echo "<script language='javascript'>window.location='AdminHome.php'</script>";
                                    }
?>
